package com.hege.config;

import com.hege.interceptor.UserInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @Author hege
 * @Date 2020/11/24 20:17
 * @Version 1.0
 */
@Configuration //定义配置类 替代xml配置
public class InterceptorConfig implements WebMvcConfigurer {

    @Autowired
    private UserInterceptor userInterceptor;

    //相当于mvc:interceptors标签
    @Override
    public void addInterceptors(InterceptorRegistry registry) {

        //拦截的路径
        String[] addPathPatterns = {

                "/user/**"
        };

        //排除的路径
        String[] excludePathPatterns = {

                "/user/out", "/user/login", "/user/errorRes"
        };

        registry.addInterceptor(userInterceptor).addPathPatterns(addPathPatterns).excludePathPatterns(excludePathPatterns);
    }
}
